/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __MEMORY_RESOURCE_H__
#define __MEMORY_RESOURCE_H__

#include "Resource.h"
#include <NoCopy.h>
#include <vector>

namespace liba
{
namespace resource
{

class Memory : public Resource, private Nocopy
{
	std::vector<char> impl;
	int position;
public:
	explicit Memory(const std::vector<char> & impl):
		impl( impl ),
		position( 0 )
	{}
	virtual bool is_valid()const
	{
		return true;
	}
	virtual int read(void * data, int count)
	{
		int real_count = std::min<int>( count, impl.size() - position );
		memmove( data, &(impl.front()) + position, real_count );
		position += real_count;
		return real_count;
	}
	virtual int skip(int count)
	{
		int real_count = std::min<int>( count, impl.size() - position );
		position += real_count;
		return real_count;
	}
	virtual int get_size()const
	{
		return impl.size();
	}
	virtual int get_position()const
	{
		return position;
	}
	virtual void reset(int position)
	{
		this->position = position;
	}
};

} // namespace resource
} // namespace liba

using namespace liba;

#endif //__MEMORY_RESOURCE_H__

